package top.wfzzq.ds;

import java.util.ArrayList;
import java.util.List;

public class MyListDemo {
         public static void main(String[] args) {
        	 //List可以记住add的次序,通过下标访问(可以理解为动态数组)
			List<String> list=new ArrayList<>();
			list.add("张三");
			list.add("李四");
			list.add("王五");
			System.out.println(list.get(1));
			list.add(1, "添加到一号位置");
			System.out.println(list.get(1));
			System.out.println("==============================================");
			for (int i = 0; i <list.size(); i++) {
				System.out.println(list.get(i));
			}
			System.out.println("==============================================");
			list.remove(0);
			for (int i = 0; i < list.size(); i++) {
				System.out.println(list.get(i));
			}
			System.out.println("自己实现的list=================================");
			MyList<String> myList=new MyList<>();
			myList.add("張三");
			myList.add("李四");
			myList.add("王五");
			System.out.println(myList.get(1));
			myList.add(1,"添加到索引1位置");
			System.out.println("===============================================");
			for(int i=0; i<myList.size(); i++) {
				System.out.println(myList.get(i));
			}
			System.out.println("===============================================");
			myList.remove(1);
			for (int i = 0; i < myList.size(); i++) {
				System.out.println(myList.get(i));
			}
		}
}
